﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EntityModel;
using Common;
using Services;
using MvcPaging;
namespace Heart.Controllers
{
    public class MethodController : Controller
    {
        //
        // GET: /Method/
        private MethodService methodService = new MethodService();
        private int pageSize = ConfigHelper.PageSize();
        public ActionResult Index(int? page)
        {
            int PageIndex = page.HasValue ? (page.Value == 0 ? 0 : (page.Value - 1)) : 0;
            var list = methodService.GetAllList().ToPagedList(PageIndex, pageSize);
            return View(list);
        }
        public ActionResult Create()
        {
            return View();
        }

        [ValidateInput(false)]
        [ActionName("Create"), AcceptVerbsAttribute("POST")]
        public ActionResult Create(FormCollection c)
        {
            this.ValidateRequest = false; 
            Method m = new Method();
            m.Name = WebBase.GetForm("Name");
            m.Contents = Server.HtmlEncode(WebBase.GetForm("Contents"));
            methodService.Create(m);
            return RedirectToAction("Index");
           
        }

    }
}
